﻿#include "main.h"
#include "_global.h"

#ifdef _DEBUG

#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)

#endif /* _DEBUG */





int main(int argc, const char* argv[]){
	int ret;
	ret=mainForLeaksDetect(argc,argv);
  leaksDetect();
	return ret;
}


int mainForLeaksDetect(int argc, const char* argv[]){


  /*
  SPtr<int> sa(SPTR_ALLOC_ON_CALL);
	*sa.p()=5;
	SPtr<int> sb=sa;
	*sb.p()=12;
  */

  //map<__int64,SPtr<FileContainer>> fileContainers;


  int a;
	a=0;


	a=1;


  /*
	int **p1;
	int **p2;

	p1=new int *[1];


	int *pd1;
	pd1=new int;
	*pd1=1;

	int *pd2;
	pd2=new int;
	*pd2=2;

	p1[0]=pd1;
	p1[0]=pd2;
	p2=p1;
	p1[0]=pd1;
  p1[0]=pd2;
	*/

  a=0;

  //ResManager RM;
	//wstring fname=L"c:/tmp/1/1.txt\0";
	//RM.addAndParseAtFile(fname);

	
	SPtr<UString> ustr1,ustr2,ustr3,ustr4,ustr5;
	SPtr<UString> ustr_langName1,ustr_langName2,ustr_langName3;
	SPtr<UString> ustr_langCaption1,ustr_langCaption2,ustr_langCaption3;
	SPtr<UString> ustr_languageCaption1,ustr_languageCaption2,ustr_languageCaption3;
	SPtr<LangPairString> langPair1,langPair2,langPair3;
	SPtr<LangPairString> languagePair1,languagePair2,languagePair3;
	SPtr<LangSelector> langSelector1;
	SPtr<LangString> langStr1;
	SPtr<FileContainer> spFCContainer1,spFCContainer2,spFCContainer3;
	SPtr<Languages> spLanguages;
	SPtr<Position> spPosition;
	SPtr<Limit> spLimit;
	SPtr<SizeXY> spSizeXY;
	SPtr<Transformation> spTransformation;

	wstring fname=L"c:/tmp/1/1.txt\0";

  /*
	//Save
	_global.RM.addAndParseAtContainer(spFCContainer1);

	_global.RM.addUString(ustr1);
	_global.RM.addUString(ustr2);
	_global.RM.addUString(ustr3);
	_global.RM.addUString(ustr4);
	_global.RM.addUString(ustr5);

	_global.RM.addUString(ustr_langName1);
	_global.RM.addUString(ustr_langName2);
	_global.RM.addUString(ustr_langName3);

	_global.RM.addUString(ustr_langCaption1);
	_global.RM.addUString(ustr_langCaption2);
	_global.RM.addUString(ustr_langCaption3);

	_global.RM.addUString(ustr_languageCaption1);
	_global.RM.addUString(ustr_languageCaption2);
	_global.RM.addUString(ustr_languageCaption3);

	_global.RM.addLangPairString(langPair1);
	_global.RM.addLangPairString(langPair2);
	_global.RM.addLangPairString(langPair3);
	
	_global.RM.addLangPairString(languagePair1);
	_global.RM.addLangPairString(languagePair2);
	_global.RM.addLangPairString(languagePair3);

	_global.RM.addLangSelector(langSelector1);

	_global.RM.addLangString(langStr1);
	_global.RM.addLanguages(spLanguages);

	_global.RM.addPosition(spPosition);
	_global.RM.addLimit(spLimit);
	_global.RM.addSizeXY(spSizeXY);
	_global.RM.addTransformation(spTransformation);

	ustr_langName1.p()->wstr=L"en";
	ustr_langName2.p()->wstr=L"ru";
	ustr_langName3.p()->wstr=L"x";

	ustr_languageCaption1.p()->wstr=L"English";
	ustr_languageCaption2.p()->wstr=L"Русский";
	ustr_languageCaption3.p()->wstr=L"Язык древний, какой-то";

	ustr_langCaption1.p()->wstr=L"English phrase";
	ustr_langCaption2.p()->wstr=L"Русская фраза";
	ustr_langCaption3.p()->wstr=L"Непереводимая игра слов";

	spPosition.p()->x=1;
	spPosition.p()->y=2;

	spLimit.p()->x=3;
  spLimit.p()->y=5;
  spLimit.p()->lx=10;
	spLimit.p()->ly=15;

	spSizeXY.p()->lx=7;
	spSizeXY.p()->ly=9;

	spTransformation.p()->clip_plx=1.0;
	spTransformation.p()->clip_ply=2.0;
	spTransformation.p()->clip_pshx=3.0;
	spTransformation.p()->clip_pshy=4.0;
	spTransformation.p()->prx=5.0;
	spTransformation.p()->pry=6.0;
	spTransformation.p()->pshx=7.0;
	spTransformation.p()->pshy=8.0;
	spTransformation.p()->scaleX=9.0;
	spTransformation.p()->scaleY=10.0;
	spTransformation.p()->rotateAngle=11;

	langPair1.p()->setLanguage(ustr_langName1);
	langPair1.p()->setCaption(ustr_langCaption1);
	langPair2.p()->setLanguage(ustr_langName2);
	langPair2.p()->setCaption(ustr_langCaption2);
	langPair3.p()->setLanguage(ustr_langName3);
	langPair3.p()->setCaption(ustr_langCaption3);

	languagePair1.p()->setLanguage(ustr_langName1);
	languagePair1.p()->setCaption(ustr_languageCaption1);
	languagePair2.p()->setLanguage(ustr_langName2);
	languagePair2.p()->setCaption(ustr_languageCaption2);
	languagePair3.p()->setLanguage(ustr_langName3);
	languagePair3.p()->setCaption(ustr_languageCaption3);
	
	spLanguages.p()->IDList_LanguageCaptions.clearIDList();
	spLanguages.p()->IDList_LanguageCaptions.addToIDList(languagePair1);
	spLanguages.p()->IDList_LanguageCaptions.addToIDList(languagePair2);
	spLanguages.p()->IDList_LanguageCaptions.addToIDList(languagePair3);

	langSelector1.p()->ID_USTRING_SelectedLanguage=langPair2.p()->getLanguage().p()->getID();
	
	langStr1.p()->IDList_langPairUStrings.clearIDList();
	langStr1.p()->IDList_langPairUStrings.addToIDList(langPair1);
	langStr1.p()->IDList_langPairUStrings.addToIDList(langPair2);
	langStr1.p()->IDList_langPairUStrings.addToIDList(langPair3);
	langStr1.p()->setLangSelector(langSelector1);
	langStr1.p()->setLanguages(spLanguages);
	
	spFCContainer1.p()->setContainerType(CT_CONTAINER);
	spFCContainer2.p()->setContainerType(CT_CONTAINER);
	spFCContainer3.p()->setContainerType(CT_CONTAINER);

	spFCContainer1.p()->setContainerCaption(L"directory1");
	spFCContainer2.p()->setContainerCaption(L"directory2");
	spFCContainer3.p()->setContainerCaption(L"directory3");

	spFCContainer3.p()->addFileContainerToChilds(ustr_langName1.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(ustr_langName2.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(ustr_langName3.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(ustr_langCaption1.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(ustr_langCaption2.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(ustr_langCaption3.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(ustr_languageCaption1.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(ustr_languageCaption2.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(ustr_languageCaption3.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(langPair1.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(langPair2.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(langPair3.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(languagePair1.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(languagePair2.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(languagePair3.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(langSelector1.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(langStr1.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(spLanguages.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(spPosition.p()->getFileContainer());
  spFCContainer3.p()->addFileContainerToChilds(spLimit.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(spSizeXY.p()->getFileContainer());
	spFCContainer3.p()->addFileContainerToChilds(spTransformation.p()->getFileContainer());
	  	
	ustr1.p()->wstr=L"abc1";
	ustr2.p()->wstr=L"def2";
	ustr3.p()->wstr=L"ghi3";
	ustr4.p()->wstr=L"jkl4";
	ustr5.p()->wstr=L"mnk5";
	
	spFCContainer2.p()->addFileContainerToChilds(ustr1.p()->getFileContainer());
	spFCContainer2.p()->addFileContainerToChilds(ustr2.p()->getFileContainer());
	spFCContainer2.p()->addFileContainerToChilds(ustr3.p()->getFileContainer());

	spFCContainer1.p()->addFileContainerToChilds(ustr4.p()->getFileContainer());
	spFCContainer1.p()->addFileContainerToChilds(spFCContainer2);
	spFCContainer1.p()->addFileContainerToChilds(ustr5.p()->getFileContainer());
  spFCContainer1.p()->addFileContainerToChilds(spFCContainer3);

	spFCContainer1.p()->setFileName(fname);

	_global.RM.saveAndJoinAll();
  */

	//Load
	_global.RM.addAndParseAtFile(fname);
	_global.RM.checkAndSetAllObjectsAtIDs();



  	
	/*
  		
	//Load
	spFCContainer1.p()->setFileName(L"c:/tmp/1/1.txt\0");
	spFCContainer1.p()->load();

	vector<SPtr<FileContainer>>::iterator iter1;
	vector<SPtr<FileContainer>>::iterator iter2;
	int i=0,j=0;
	
	for(iter1=(spFCContainer1.p()->getChilds())->begin();iter1!=(spFCContainer1.p()->getChilds())->end();iter1++){
		i++;
		if(i==1)ustr4.setFileContainer((*iter1));
		if(i==2){
			spFCContainer2=*iter1;
			for(iter2=(spFCContainer2.p()->getChilds())->begin();iter2!=(spFCContainer2.p()->getChilds())->end();iter2++){
		    j++;
		    if(j==1)ustr1.setFileContainer((*iter2));
				if(j==2)ustr2.setFileContainer((*iter2));
				if(j==3)ustr3.setFileContainer((*iter2));
	    }
		}
		if(i==3)ustr5.setFileContainer((*iter1));
	}

	ustr1.parse();
	ustr2.parse();
	ustr3.parse();
	ustr4.parse();
	ustr5.parse();
  */
	a=0;

  return 0;
}


void leaksDetect(){
	//_global.~_Global();
  //_CrtDumpMemoryLeaks();
}